package com.a9_lin.www.testormlite.bean;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.field.ForeignCollectionField;
import com.j256.ormlite.table.DatabaseTable;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

/**
 * Created by macmini on 16/10/26.
 */
@DatabaseTable(tableName = "tb_userinfolist")
public class UserInfoListBean implements Serializable {

    @DatabaseField(generatedId = true)
    private int id;

    //这里我们需要给外键设置这个注解
    @ForeignCollectionField(eager = true)
    private Collection<Userinfo> userinfos;

    public Collection<Userinfo> getUserinfos() {
        return userinfos;
    }

    public void setUserinfos(Collection<Userinfo> userinfos) {
        this.userinfos = userinfos;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "UserInfoListBean{" +
                "id=" + id +
                ", userinfos=" +
                // TODO: 16/10/27  这里需要注意的是 如果我们的数据是从数据库中取出来的话 数据格式是ForeignCollection 需要转换为我们需要的集合类型使用
                (userinfos==null?"null":new ArrayList<>(userinfos)) +
                '}';
    }
}
